﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using HRM.CORE;
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xucRecruitmentAdd : Common.xucBaseAdd
    {
        private ImageComboBoxEdit cboStatus;
        private IContainer components = null;
        private DateEdit dtFromDate;
        private DateEdit dtToDate;
        private DevExpress.Utils.ImageCollection imgStatus;
        private LabelControl labelControl5;
        private LabelControl lcDecideNumber;
        private LabelControl lcDescription;
        private LabelControl lcFromDate;
        private LabelControl lcQuantity;
        private LabelControl lcStatus;
        private LabelControl lcToDate;
        private TextEdit txtDecideNumber;
        private TextEdit txtDescription;
        private ButtonEdit txtFilePath;
        private CalcEdit txtQuantity;

        public event SuccessEventHander Success;

        public xucRecruitmentAdd()
        {
            this.InitializeComponent();
            this.InitMultiLanguages();
            this.cboStatus.SelectedIndex = 0;
            this.txtQuantity.EditValue = 0;
            this.dtFromDate.DateTime = System.DateTime.Now;
            this.dtToDate.DateTime = System.DateTime.Now;
        }

        protected override void Add()
        {
            base.Add();
            base.txtID.Text = new HRM_RECRUITMENT().NewID();
            base.txtNAME.Focus();
        }

        public void Clear()
        {
            base.txtID.Text = "";
            base.txtNAME.Text = "";
            this.txtDecideNumber.Text = "";
            this.dtFromDate.DateTime = System.DateTime.Now;
            this.dtToDate.DateTime = System.DateTime.Now;
            this.txtQuantity.EditValue = 0;
            this.txtFilePath.Text = "";
            this.cboStatus.SelectedIndex = 0;
            this.txtDescription.Text = "";
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        protected override void Init()
        {
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucRecruitmentAdd));
            SerializableAppearanceObject appearance = new SerializableAppearanceObject();
            this.dtFromDate = new DateEdit();
            this.dtToDate = new DateEdit();
            this.txtDescription = new TextEdit();
            this.lcDescription = new LabelControl();
            this.lcFromDate = new LabelControl();
            this.lcToDate = new LabelControl();
            this.lcStatus = new LabelControl();
            this.labelControl5 = new LabelControl();
            this.txtFilePath = new ButtonEdit();
            this.cboStatus = new ImageComboBoxEdit();
            this.imgStatus = new DevExpress.Utils.ImageCollection(this.components);
            this.txtDecideNumber = new TextEdit();
            this.lcDecideNumber = new LabelControl();
            this.lcQuantity = new LabelControl();
            this.txtQuantity = new CalcEdit();
            base.gcInfo.BeginInit();
            base.gcInfo.SuspendLayout();
            base.txtNAME.Properties.BeginInit();
            base.txtID.Properties.BeginInit();
            base.imageCollection2.BeginInit();
            ((ISupportInitialize) base.Err).BeginInit();
            this.dtFromDate.Properties.VistaTimeProperties.BeginInit();
            this.dtFromDate.Properties.BeginInit();
            this.dtToDate.Properties.VistaTimeProperties.BeginInit();
            this.dtToDate.Properties.BeginInit();
            this.txtDescription.Properties.BeginInit();
            this.txtFilePath.Properties.BeginInit();
            this.cboStatus.Properties.BeginInit();
            this.imgStatus.BeginInit();
            this.txtDecideNumber.Properties.BeginInit();
            this.txtQuantity.Properties.BeginInit();
            base.SuspendLayout();
            base.gcInfo.Controls.Add(this.lcQuantity);
            base.gcInfo.Controls.Add(this.txtQuantity);
            base.gcInfo.Controls.Add(this.txtDecideNumber);
            base.gcInfo.Controls.Add(this.lcDecideNumber);
            base.gcInfo.Controls.Add(this.txtFilePath);
            base.gcInfo.Controls.Add(this.labelControl5);
            base.gcInfo.Controls.Add(this.lcStatus);
            base.gcInfo.Controls.Add(this.lcToDate);
            base.gcInfo.Controls.Add(this.lcFromDate);
            base.gcInfo.Controls.Add(this.txtDescription);
            base.gcInfo.Controls.Add(this.lcDescription);
            base.gcInfo.Controls.Add(this.dtToDate);
            base.gcInfo.Controls.Add(this.dtFromDate);
            base.gcInfo.Controls.Add(this.cboStatus);
            base.gcInfo.Size = new Size(0x17f, 0xc4);
            base.gcInfo.TabIndex = 0;
            base.gcInfo.Controls.SetChildIndex(this.cboStatus, 0);
            base.gcInfo.Controls.SetChildIndex(this.dtFromDate, 0);
            base.gcInfo.Controls.SetChildIndex(this.dtToDate, 0);
            base.gcInfo.Controls.SetChildIndex(base.lblId, 0);
            base.gcInfo.Controls.SetChildIndex(base.txtID, 0);
            base.gcInfo.Controls.SetChildIndex(base.lblName, 0);
            base.gcInfo.Controls.SetChildIndex(base.txtNAME, 0);
            base.gcInfo.Controls.SetChildIndex(this.lcDescription, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtDescription, 0);
            base.gcInfo.Controls.SetChildIndex(this.lcFromDate, 0);
            base.gcInfo.Controls.SetChildIndex(this.lcToDate, 0);
            base.gcInfo.Controls.SetChildIndex(this.lcStatus, 0);
            base.gcInfo.Controls.SetChildIndex(this.labelControl5, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtFilePath, 0);
            base.gcInfo.Controls.SetChildIndex(this.lcDecideNumber, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtDecideNumber, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtQuantity, 0);
            base.gcInfo.Controls.SetChildIndex(this.lcQuantity, 0);
            base.txtNAME.Location = new Point(0xc5, 0x1b);
            base.txtNAME.Size = new Size(0xb0, 20);
            base.lblName.Location = new Point(0xae, 30);
            base.txtID.Location = new Point(0x3e, 0x1a);
            base.txtID.Size = new Size(0x65, 20);
            base.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            base.btnSave.Location = new Point(0x5c, 0xcc);
            base.btnSave.TabIndex = 1;
            base.btnCancel.Location = new Point(0x117, 0xcc);
            base.btnCancel.TabIndex = 3;
            base.btnSaveNew.Location = new Point(0xba, 0xcc);
            base.btnSaveNew.TabIndex = 2;
            this.dtFromDate.EditValue = null;
            this.dtFromDate.Location = new Point(0x3f, 0x36);
            this.dtFromDate.Name = "dtFromDate";
            this.dtFromDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtFromDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtFromDate.Size = new Size(100, 20);
            this.dtFromDate.TabIndex = 5;
            this.dtToDate.EditValue = null;
            this.dtToDate.Location = new Point(0xf5, 0x36);
            this.dtToDate.Name = "dtToDate";
            this.dtToDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtToDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtToDate.Size = new Size(0x80, 20);
            this.dtToDate.TabIndex = 7;
            this.txtDescription.Location = new Point(0x3f, 0x89);
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Size = new Size(310, 20);
            this.txtDescription.TabIndex = 15;
            this.lcDescription.Location = new Point(9, 140);
            this.lcDescription.Name = "lcDescription";
            this.lcDescription.Size = new Size(0x27, 13);
            this.lcDescription.TabIndex = 14;
            this.lcDescription.Text = "Ghi ch\x00fa:";
            this.lcFromDate.Location = new Point(6, 0x39);
            this.lcFromDate.Name = "lcFromDate";
            this.lcFromDate.Size = new Size(0x2c, 13);
            this.lcFromDate.TabIndex = 4;
            this.lcFromDate.Text = "Từ ng\x00e0y:";
            this.lcToDate.Location = new Point(0xbb, 0x39);
            this.lcToDate.Name = "lcToDate";
            this.lcToDate.Size = new Size(0x33, 13);
            this.lcToDate.TabIndex = 6;
            this.lcToDate.Text = "Đến ng\x00e0y:";
            this.lcStatus.Location = new Point(7, 0x70);
            this.lcStatus.Name = "lcStatus";
            this.lcStatus.Size = new Size(0x35, 13);
            this.lcStatus.TabIndex = 12;
            this.lcStatus.Text = "Trạng th\x00e1i:";
            this.labelControl5.Location = new Point(9, 0xa8);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(20, 13);
            this.labelControl5.TabIndex = 0x10;
            this.labelControl5.Text = "File:";
            this.txtFilePath.Location = new Point(0x3f, 0xa5);
            this.txtFilePath.Name = "txtFilePath";
            this.txtFilePath.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Glyph, "", -1, true, true, false, ImageLocation.MiddleCenter, (Image) manager.GetObject("txtFilePath.Properties.Buttons"), new KeyShortcut(Keys.None), appearance, "", "Browse", null, true) });
            this.txtFilePath.Properties.ButtonClick += new ButtonPressedEventHandler(this.txtFilePath_Properties_ButtonClick);
            this.txtFilePath.Size = new Size(310, 0x16);
            this.txtFilePath.TabIndex = 0x11;
            this.cboStatus.Location = new Point(0x3f, 0x6d);
            this.cboStatus.Name = "cboStatus";
            this.cboStatus.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cboStatus.Properties.Items.AddRange(new ImageComboBoxItem[] { new ImageComboBoxItem("Đang l\x00ean kế hoạch", "Đang l\x00ean kế hoạch", 1), new ImageComboBoxItem("Đang thực hiện tuyển dụng", "Đang thực hiện tuyển dụng", 2), new ImageComboBoxItem("Đ\x00e3 ho\x00e0n th\x00e0nh", "Đ\x00e3 ho\x00e0n th\x00e0nh", 0) });
            this.cboStatus.Properties.SmallImages = this.imgStatus;
            this.cboStatus.Size = new Size(310, 20);
            this.cboStatus.TabIndex = 13;
            this.cboStatus.TabStop = false;
            this.imgStatus.ImageStream = (ImageCollectionStreamer) manager.GetObject("imgStatus.ImageStream");
            this.imgStatus.Images.SetKeyName(0, "marker_rounded_red.png");
            this.imgStatus.Images.SetKeyName(1, "marker_rounded_grey_4.png");
            this.imgStatus.Images.SetKeyName(2, "marker_rounded_orrange.png");
            this.txtDecideNumber.Location = new Point(0xf5, 0x52);
            this.txtDecideNumber.Name = "txtDecideNumber";
            this.txtDecideNumber.Size = new Size(0x80, 20);
            this.txtDecideNumber.TabIndex = 11;
            this.lcDecideNumber.Location = new Point(0xa9, 0x55);
            this.lcDecideNumber.Name = "lcDecideNumber";
            this.lcDecideNumber.Size = new Size(70, 13);
            this.lcDecideNumber.TabIndex = 10;
            this.lcDecideNumber.Text = "Số quyết định:";
            this.lcQuantity.Location = new Point(7, 0x55);
            this.lcQuantity.Name = "lcQuantity";
            this.lcQuantity.Size = new Size(0x2e, 13);
            this.lcQuantity.TabIndex = 8;
            this.lcQuantity.Text = "Số lượng:";
            this.txtQuantity.Location = new Point(0x3f, 0x52);
            this.txtQuantity.Name = "txtQuantity";
            this.txtQuantity.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.txtQuantity.Size = new Size(100, 20);
            this.txtQuantity.TabIndex = 9;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Name = "xucRecruitmentAdd";
            base.Size = new Size(0x182, 240);
            base.gcInfo.EndInit();
            base.gcInfo.ResumeLayout(false);
            base.gcInfo.PerformLayout();
            base.txtNAME.Properties.EndInit();
            base.txtID.Properties.EndInit();
            base.imageCollection2.EndInit();
            ((ISupportInitialize) base.Err).EndInit();
            this.dtFromDate.Properties.VistaTimeProperties.EndInit();
            this.dtFromDate.Properties.EndInit();
            this.dtToDate.Properties.VistaTimeProperties.EndInit();
            this.dtToDate.Properties.EndInit();
            this.txtDescription.Properties.EndInit();
            this.txtFilePath.Properties.EndInit();
            this.cboStatus.Properties.EndInit();
            this.imgStatus.EndInit();
            this.txtDecideNumber.Properties.EndInit();
            this.txtQuantity.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "Recruitment", this.Text);
            this.lcFromDate.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "FromDate", this.lcFromDate.Text);
            this.lcToDate.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "ToDate", this.lcToDate.Text);
            this.lcQuantity.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "Quantity", this.lcQuantity.Text);
            this.lcDecideNumber.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "DecideNumber", this.lcDecideNumber.Text);
            this.lcStatus.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "Status", this.lcStatus.Text);
            this.lcDescription.Text = MultiLanguages.GetString("tbl_RecruitmentAdd", "Description", this.lcDescription.Text);
        }

        private void RaiseSuccessEventHander(HRM_RECRUITMENT item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        public void SetData(HRM_RECRUITMENT item)
        {
            base.txtID.Text = item.RecruitmentCode;
            SYS_LOG.Insert("Danh Mục Chức Vụ", "Xem", base.txtID.Text);
            if (base.m_Status == Actions.Update)
            {
                base.txtID.Properties.ReadOnly = true;
            }
            base.txtNAME.Text = item.RecruitmentName;
            this.dtFromDate.DateTime = item.FromDate;
            this.dtToDate.DateTime = item.ToDate;
            this.txtQuantity.EditValue = item.Quantity;
            this.txtDecideNumber.Text = item.DecideNumber;
            this.txtFilePath.Text = item.FilePath;
            this.cboStatus.SelectedIndex = item.Status;
            this.txtDescription.Text = item.Description;
        }

        private void txtFilePath_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "All File(*.*)|*.*",
                FilterIndex = 0
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtFilePath.Text = dialog.FileName;
            }
        }

        protected override void txtID_EditValueChanged(object sender, EventArgs e)
        {
            TextEdit control = (TextEdit) sender;
            if (control.ErrorText != string.Empty)
            {
                base.Err.SetError(control, string.Empty);
            }
            if (base.m_Status == Actions.Add)
            {
                HRM_RECRUITMENT hrm_recruitment = new HRM_RECRUITMENT();
                if (hrm_recruitment.Exist(control.Text))
                {
                    base.Err.SetError(control, "M\x00e3 đ\x00e3 tồn tại.");
                    control.Focus();
                }
            }
        }

        protected override void txtID_KeyDown(object sender, KeyEventArgs e)
        {
            TextEdit control = (TextEdit) sender;
            if ((e.KeyCode == Keys.Enter) | (e.KeyCode == Keys.Tab))
            {
                HRM_RECRUITMENT hrm_recruitment = new HRM_RECRUITMENT();
                if ((base.m_Status == Actions.Add) && hrm_recruitment.Exist(control.Text))
                {
                    base.Err.SetError(control, "M\x00e3 đ\x00e3 tồn tại.");
                    control.Focus();
                }
            }
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            HRM_RECRUITMENT item = new HRM_RECRUITMENT {
                RecruitmentCode = base.txtID.Text
            };
            string str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            SYS_LOG.Insert("Đợt Tuyển Dụng", "Th\x00eam", base.txtID.Text);
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            Cursor.Current = Cursors.WaitCursor;
            HRM_RECRUITMENT item = new HRM_RECRUITMENT(base.txtID.Text, base.txtNAME.Text, this.dtFromDate.DateTime, this.dtToDate.DateTime, int.Parse(this.txtQuantity.EditValue.ToString()), this.txtDecideNumber.Text, this.txtFilePath.Text, this.cboStatus.SelectedIndex, this.txtDescription.Text);
            string text = item.Insert();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            Cursor.Current = Cursors.Default;
            this.DoHide();
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return text;
        }

        protected override string uc_Update()
        {
            SYS_LOG.Insert("Quản L\x00fd Bộ Phận", "Cập Nhật", base.txtID.Text);
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            HRM_RECRUITMENT item = new HRM_RECRUITMENT(base.txtID.Text, base.txtNAME.Text, this.dtFromDate.DateTime, this.dtToDate.DateTime, int.Parse(this.txtQuantity.EditValue.ToString()), this.txtDecideNumber.Text, this.txtFilePath.Text, this.cboStatus.SelectedIndex, this.txtDescription.Text);
            string text = item.Update();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        public delegate void SuccessEventHander(object sender, HRM_RECRUITMENT item);
    }
}

